package com.donglink.project.logmonitor;

import com.donglink.project.logmonitor.bolt.FilterBolt;
import com.donglink.project.logmonitor.bolt.NotifyBolt;
import com.donglink.project.logmonitor.bolt.SaveBolt;
import com.donglink.project.logmonitor.spout.MySpout;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.topology.TopologyBuilder;

public class LogMonitorDriver {
    public static void main(String[] args) {

        //建立拓扑
        TopologyBuilder builder=new TopologyBuilder();

        //自定义产生日志的spout
        builder.setSpout("inputSpout",new MySpout(),3);
        //检测是否符合告警规则，过滤掉不符合告警规则的日志
        builder.setBolt("filterBolt",new FilterBolt(),3).globalGrouping("inputSpout");
        //发送告警到邮箱或者发送短信
        builder.setBolt("notifyBolt",new NotifyBolt(),3).globalGrouping("filterBolt");
        //将每一条触发规则的告警信息保存进数据库中
        builder.setBolt("saveBolt",new SaveBolt(),3).globalGrouping("notifyBolt");




        //设置worker数量
        Config configp=new Config();
        configp.setNumWorkers(3);

        //本地运行指定的拓扑
        LocalCluster localCluster=new LocalCluster();
        localCluster.submitTopology("logmonitor",configp,builder.createTopology());

    }
}
